<template>
  <div class="bigBox">
    <div class="topBox">
      <div class="leftBox">
        <div class="title">
          <div class="blueLine">
            已完成单据数量
          </div>
        </div>
        <div class="right">
          <div class="imgBox" style="background-color: #a8dbd0;">
            <img style="width:30px;height:30px;text-align: center;" src="@/assets/images/rkds.png" alt="" />
          </div>
          <div>{{FinishBillsNum[0]&&FinishBillsNum[0].Finish_Bills_Num?FinishBillsNum[0].Finish_Bills_Num:0}}</div>
        </div>
      </div>
      <div class="leftBox">
        <div class="title">
          <div class="blueLine">
            已完商品种类数量
          </div>
        </div>
        <div class="right">
          <div class="imgBox" style="background-color: #ebd1ec;">
            <img style="width:30px;height:30px;text-align: center;" src="@/assets/images/rkzs.png" alt="" />
          </div>
          <div>{{totalList[0]&&totalList[0].Sku_Class_Num?totalList[0].Sku_Class_Num:0}}</div>
        </div>
      </div>
      <div class="leftBox">
        <div class="title">
          <div class="blueLine">
            已完成商品数量
          </div>
        </div>
        <div class="right">
          <div class="imgBox">
            <img style="width:30px;height:30px;text-align: center;" src="@/assets/images/bhe.png" alt="" />
          </div>
          <div>{{ totalList[0]&&totalList[0].Sku_All_Num?totalList[0].Sku_All_Num:0 }}</div>
        </div>
      </div>
      <div class="leftBox">
        <div class="title">
          <div class="blueLine">
            未完成单据数量
          </div>
        </div>
        <div class="right">
          <div class="imgBox" style="background-color: #a8dbd0;">
            <img style="width:30px;height:30px;text-align: center;" src="@/assets/images/cppl.png" alt="" />
          </div>
          <div>{{NofinishNum[0]&&NofinishNum[0].NofinishNum?NofinishNum[0].NofinishNum:0}}</div>
        </div>
      </div>
      <div class="leftBox">
        <div class="title">
          <div class="blueLine">
            入库时间
          </div>
        </div>
        <div class="right">
          <el-radio-group v-model="formList.radio1">
            <el-radio-button label="1">今天</el-radio-button>
            <el-radio-button label="2">本周</el-radio-button>
            <el-radio-button label="3">本月</el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div class="leftBox">
        <div class="title">
          <div class="blueLine">
            仓库
          </div>
          <div>
            <el-dropdown @command="handleCommand">
              <span class="el-dropdown-link">
                {{chooseSto}}<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="1">等于</el-dropdown-item>
                <el-dropdown-item command="2">不等于</el-dropdown-item>
                <el-dropdown-item command="3">全部</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </div>
        <div class="right">
          <el-select v-model="formList.wareHouseName" placeholder="请选择仓库" clearable :style="{ width: '100%' }"
            filterable @change="getWareHouse">
            <el-option v-for="item in warehouses"
              :label="item.cwarehouse_name?item.cwarehouse_name:item.cwarehouse_name"
              :value="item.cwarehouse_id?item.cwarehouse_id:111" />
          </el-select>
        </div>
      </div>
      <div class="leftBox">
        <div class="title">
          <div class="blueLine">
            供应商
          </div>
          <div>
            <el-dropdown @command="supplierhandleCommand">
              <span class="el-dropdown-link">
                {{chooseSupply}}<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="1">等于</el-dropdown-item>
                <el-dropdown-item command="2">不等于</el-dropdown-item>
                <el-dropdown-item command="3">全部</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </div>
        <div class="right">
          <el-select v-model="formList.supplierValue" placeholder="请选择供应商" clearable :style="{ width: '100%' }"
            filterable @change="getSupplier">
            <el-option v-for="item in suppliers" :label="item?item.vsender_name:'无'"
              :value="item?item.vsender_id:'111'" />
          </el-select>
        </div>
      </div>
      <div class="leftBox">
        <div class="title">
          <div class="blueLine">
            产品
          </div>
          <div>
            <el-dropdown @command="goodshandleCommand">
              <span class="el-dropdown-link">
                {{chooseSku}}<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="1">等于</el-dropdown-item>
                <el-dropdown-item command="2">不等于</el-dropdown-item>
                <el-dropdown-item command="3">全部</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </div>
        <div class="right">
          <el-select v-model="formList.SkuId" placeholder="请选择产品" clearable :style="{ width: '100%' }" filterable
            @change="getGoods">
            <el-option v-for="item in goodsList" :label="item.material_name" :value="item.pk_material" />
          </el-select>
        </div>
      </div>
    </div>
    <el-row>
      <el-col :span="12">
        <div class="areaChart" style="margin-right: 15px;">
          <AreaChartD :echartsData="echartsData" />
        </div>
      </el-col>
      <el-col :span="12">
        <div class="areaChart">
          <top10Other :echarts10Data="echarts10Data" />
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div class="areaChart">
          <el-tabs v-model="activeName">
            <el-tab-pane label="已完成单据" name="first">
              <otherTable :tableList="tableList"/>
            </el-tab-pane>
            <el-tab-pane label="未完成单据" name="second">
              <billsNoFinsh :tableList="NofinishList"/>
            </el-tab-pane>
          </el-tabs>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import {
    getWarehouseInBasic, //获取下拉框
    getWarehouseInStatistic, //入库统计数据
    getWarehouseInNoFinishBills //未完成单据
  } from "@/api/report/index.js";
  import AreaChartD from './other/areaChartD.vue'
  import otherTable from './other/otherTable.vue'
  import top10Other from './other/top10Other.vue'
  import billsNoFinsh from './other/billsNoFinsh.vue'
  export default {
    name: 'otherBuyOrder',
    components: {
      AreaChartD,
      otherTable,
      top10Other,
      billsNoFinsh
    },
    data() {
      return {
        formList: {
          radio1: '1',
          wareHouseName: '',
          supplierValue: '',
          senderId: '',
          wareHouseValue: 3,
          SenderValue: 3,
          SkuId: '',
          SkuIdValue: 3
        },
        warehouses: [],
        suppliers: [],
        echartsData: [], //折线数据
        tableList: [],
        totalList: [],
        FinishBillsNum: [],
        echarts10Data: [],
        goodsList: [], //产品
        NofinishNum: [], //未完成单据数量
        NofinishList: [], //未完成单据明细
        chooseSto: '全部',
        chooseSupply: '全部',
        chooseSku: '全部',
        activeName:'first'//默认显示已完成单据
      }
    },
    created() {
      this.getData();
      this.getTotal();
      this.getNoFinish();
    },
    watch: {
      // 监听 formList.radio1 的变化
      'formList.radio1'(newValue, oldValue) {
        this.getData(newValue);
        this.getTotal(newValue);
        this.getNoFinish(newValue);
      }
    },
    methods: {
      //未完成单据统计
      getNoFinish(data) {
        let param = {
          dataType: data ? data : this.formList.radio1,
          wareHouseMode: 'OtherWareHouseIn',
        }
        getWarehouseInNoFinishBills(param).then(res => {
          if (res.data) {
            this.NofinishNum = res.data.type0 || [];
            this.NofinishList = res.data.type1 || [];
          }
        })
      },
      //下拉条件菜单
      handleCommand(command) {
        switch (command) {
          case '1':
            this.chooseSto = '等于';
            this.formList.wareHouseValue = command;
            this.getTotal();
            break;
          case '2':
            this.chooseSto = '不等于';
            this.formList.wareHouseValue = command;
            this.getTotal();
            break;
          case '3':
            this.chooseSto = '全部';
            this.formList.wareHouseValue = command;
            this.getTotal();
            break;
        }
      },
      //产品下拉
      goodshandleCommand(command) {
        switch (command) {
          case '1':
            this.chooseSku = '等于';
            this.formList.SkuIdValue = command;
            this.getTotal();
            break;
          case '2':
            this.chooseSku = '不等于';
            this.formList.SkuIdValue = command;
            this.getTotal();
            break;
          case '3':
            this.chooseSku = '全部';
            this.formList.SkuIdValue = command;
            this.getTotal();
            break;
        }
      },
      //供应商下拉
      supplierhandleCommand(command) {
        switch (command) {
          case '1':
            this.chooseSupply = '等于';
            this.formList.SenderValue = command;
            this.getTotal();
            break;
          case '2':
            this.chooseSupply = '不等于';
            this.formList.SenderValue = command;
            this.getTotal();
            break;
          case '3':
            this.chooseSupply = '全部';
            this.formList.SenderValue = command;
            this.getTotal();
            break;
        }
      },
      //初始化基础数据
      getData(data) {
        let param = {
          dataType: data ? data : this.formList.radio1,
          wareHouseMode: 'OtherWareHouseIn '
        };
        getWarehouseInBasic(param).then(res => {
          this.warehouses = res.data.type1 || [];
          this.suppliers = res.data.type3 || [];
          this.goodsList = res.data.type2 || []
        }).catch(error => {
          this.$message.error('获取仓库和供应商数据失败:', error);
        });
      },
      //获取产品
      getGoods(val) {
        this.formList.SkuId = val;
        this.getTotal();
      },
      //切换仓库
      getWareHouse(val) {
        this.formList.wareHouseName = val;
        this.getTotal();
      },
      //切换供应商
      getSupplier(val) {
        this.formList.supplierValue = val;
        this.getTotal();
      },
      //入库统计
      getTotal(data) {
        let param = {
          dataType: data ? data : this.formList.radio1,
          wareHouseMode: 'OtherWareHouseIn ',
          senderId: this.formList.supplierValue,
          wareHouseName: this.formList.wareHouseName,
          senderValue: this.formList.SenderValue,
          wareHouseValue: this.formList.wareHouseValue,
          SkuId: this.formList.SkuId,
          SkuIdValue: this.formList.SkuIdValue
        };
        getWarehouseInStatistic(param).then(res => {
          // 检查接口返回数据的结构
          if (res.data) {
            this.echartsData = res.data.type4 || [];
            this.tableList = res.data.type3 || [];
            this.totalList = res.data.type2 || [];
            this.FinishBillsNum = res.data.type1 || [];
            this.echarts10Data = res.data.type5 || []
          }
        }).catch(error => {
          this.$message.error('获取入库统计数据失败:', error);
        });
      }
    },
  }
</script>
<style scoped lang="scss">
  .topBox {
    flex-wrap: wrap;
    display: flex;
    gap: 0 15px;
  }

  //曲线图
  .areaChart {
    border: 1px solid #e1e1e1;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 5px 5px 10px 0px rgba(0, 0, 0, 0.1);
  }

  .blueLine {
    display: flex;
    align-items: center;
  }

  //下拉菜单
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }

  .el-icon-arrow-down {
    font-size: 12px;
  }

  .blueLine:before {
    content: "";
    background: #8cc5ff;
    display: block;
    width: 6px;
    height: 20px;
    margin-right: 10px;

  }

  .leftBox:nth-child(2n) .right {
    display: flex;
    align-items: center;
    justify-content: space-around;
  }

  .imgBox {
    width: 50px;
    height: 50px;
    border-radius: 5px;
    background-color: #eef7ff;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .leftBox {
    margin-bottom: 10px;
    padding: 0 10px;
    height: 150px;
    width: calc(25% - 12px);
    border-radius: 10px;
    border: 1px solid #e1e1e1;
    box-shadow: 5px 5px 10px 0px rgba(0, 0, 0, 0.1);
    flex-wrap: wrap;

    .title {
      justify-content: space-between;
      display: flex;
      align-items: center;
      color: #333333;
      font-weight: bold;
      padding: 10px 0px;
      font-size: 18px;
    }

    .right {
      display: flex;
      align-items: center;
      justify-content: space-evenly;
      font-size: 30px;
      color: #409EFF;
      line-height: 100px;
      font-weight: bold;
    }
  }


  .el-radio-group {
    line-height: 100px;
  }

  .el-row {
    margin-top: 10px;
  }

  ::v-deep .el-input--suffix {
    height: 70px;
  }

  @media (max-width: 1200px) {
    .leftBox {
      width: calc(25% - 8px);
      /* 每行4个卡片 */
    }
  }

  @media (max-width: 768px) {
    .leftBox {
      width: calc(50% - 8px);
      /* 每行2个卡片 */
    }
  }

  @media (max-width: 480px) {
    .leftBox {
      width: 100%;
      /* 每行1个卡片 */
    }
  }
</style>
